<template>
  <div class="modifyUser">
    <div class="user" v-if="isshow">
      <el-form
        :inline="true"
        :model="userinfo"
        class="demo-form-inline"
        label-position="right"
        label-width="80px"
      >
        <el-form-item label="账号">
          <el-input
            v-model="userinfo.userPhone"
            :disabled="true"
            placeholder="手机号"
          ></el-input>
        </el-form-item>
        <el-form-item label="用户姓名">
          <el-input
            v-model="userinfo.usermessageName"
            placeholder="请输入姓名"
          ></el-input>
        </el-form-item>
        <el-form-item label="角色">
          <el-input
            v-model="userinfo.usermessageType"
            placeholder="职务"
          ></el-input>
        </el-form-item>
        <!-- <el-form-item label="角色ID">
          <el-input
            v-model="userinfo.usermessageId"
            placeholder="ID值"
          ></el-input>
        </el-form-item> -->
        <el-form-item label="工号">
          <el-input
            v-model="userinfo.usermessageJobnumber"
            placeholder="纯数字"
          ></el-input>
        </el-form-item>
      </el-form>
      <div class="operation">
        <el-Button @click="submit(userinfo)">保存</el-Button>
        <el-Button @click="isshow = false">关闭</el-Button>
      </div>
    </div>
  </div>
</template>

<script>
import { userModifyInfo } from "@/network/api/userme/userme";
import mitt from "@/utils/mitt";
export default {
  name: "User",
  data() {
    return {
      isshow: false,
      userinfo: {
        usermessageName: "",
        userPhone: "",
        usermessageType: "",
        usermessageJobnumber: "",
        // usermessageId: 0,
      },
    };
  },
  created() {
    mitt.on("isshowU", (res) => {
      this.isshow = res;
    });

    mitt.on("infolist", (res) => {
      console.log(res, 222222);
      this.userinfo.userPhone = res.userPhone;
    });
  },
  methods: {
    async submit(data) {
      console.log(data);
      if (typeof data.usermessageJobnumber != "number") {
        alert("工号为纯数字");
        return;
      }

      data.usermessageJobnumber = String(data.usermessageJobnumber);
      console.log(data, "修改信息");
      let info = await userModifyInfo(data);
      this.userinfo = {};
      this.isshow = false;
      console.log(info, "修改后");
    },
  },
};
</script>

<style scoped lang='scss'>
.modifyUser {
  width: 100%;
  height: 100%;
  position: relative;
  .user {
    width: 55%;
    padding: 20px 30px;
    box-sizing: border-box;
    border-radius: 10px;
    background-color: rgb(194, 233, 239);
    position: absolute;
    top: -280px;
    left: 300px;
    z-index: 99;
  }
  .operation {
    text-align: center;
  }
}
</style>